package com.csdj.t301.cloud;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.FileHandler;

/**
 * author:cloud
 * date:2021/1/21 0021
 **/
public class StudentRelfectTest {
    public static void main(String[] args) {
        try {
            Class clazz = Class.forName("com.csdj.t301.cloud.entity.Student");
            Object obj = clazz.newInstance();
            Field nameField = clazz.getDeclaredField("name");
            Field ageField = clazz.getDeclaredField("age");
            nameField.setAccessible(true);
            ageField.setAccessible(true);
            nameField.set(obj,"name");
            ageField.set(obj,23);
            Method method = clazz.getDeclaredMethod("sing",String.class);

            Object target = method.invoke(obj,"do somegddd");
            System.out.println(target.toString());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

    }
}
